cap log close
log using "$logs/an-iat-sensitivity.log", replace

use "$data/iat", clear
keep if k12==1

// Merge with covariates
merge m:1 countyid using "$data/seda_covariates_clean", nogen

est clear

// Models...

eststo: mixed implicitbias ///
	i.schoolyear || fips: ||countyid: 
	estat icc
	estadd scalar icc_county= r(icc2)
	estadd scalar icc_state= r(icc3)
	mat define n=e(N_g)
	estadd scalar county_n=n[1,2]
	
	esttab using "$output/an-iat-sensitivity-fullsample.csv", compress nogaps se replace title("Multilevel Models Predicting IAT Scores, Educators only (2009-2016)") ///
		note("Note: All models include random intercepts for county nested within state and year FE.") ///
		scalar(icc_county icc_state county_n) ///
		transform(ln*: exp(@) exp(@)) ///
		eqlabels("" "sd(state)" "sd(county)" "sd(residual)", none) 
	   
eststo: mixed implicitbias ///
	amind eastasian southasian nathaw black blackwhite multiother otherun ///
	female i.agecat i.ed ///
	i.schoolyear || fips: ||countyid: 
	estat icc
	estadd scalar icc_county= r(icc2)
	estadd scalar icc_state= r(icc3)
	mat define n=e(N_g)
	estadd scalar county_n=n[1,2]
	
	esttab using "$output/an-iat-sensitivity-fullsample.csv", compress nogaps se replace title("Multilevel Models Predicting IAT Scores, Educators only (2009-2016)") ///
		note("Note: All models include random intercepts for county nested within state and year FE.") ///
		scalar(icc_county icc_state county_n) ///
		transform(ln*: exp(@) exp(@)) ///
		eqlabels("" "sd(state)" "sd(county)" "sd(residual)", none) 
		
eststo: mixed implicitbias ///
	sesall ///
	i.schoolyear || fips: ||countyid: 
	estat icc
	estadd scalar icc_county= r(icc2)
	estadd scalar icc_state= r(icc3)
	mat define n=e(N_g)
	estadd scalar county_n=n[1,2]
	
	esttab using "$output/an-iat-sensitivity-fullsample.csv", compress nogaps se replace title("Multilevel Models Predicting IAT Scores, Educators only (2009-2016)") ///
		note("Note: All models include random intercepts for county nested within state and year FE.") ///
		scalar(icc_county icc_state county_n) ///
		transform(ln*: exp(@) exp(@)) ///
		eqlabels("" "sd(state)" "sd(county)" "sd(residual)", none) 		
		
eststo: mixed implicitbias ///
	perblk perhsp /*pctenglish1*/ hswhtblk hsflnfl percharter_all ///
	i.schoolyear || fips: ||countyid: 
	estat icc
	estadd scalar icc_county= r(icc2)
	estadd scalar icc_state= r(icc3)
	mat define n=e(N_g)
	estadd scalar county_n=n[1,2]
	
	esttab using "$output/an-iat-sensitivity-fullsample.csv", compress nogaps se replace title("Multilevel Models Predicting IAT Scores, Educators only (2009-2016)") ///
		note("Note: All models include random intercepts for county nested within state and year FE.") ///
		scalar(icc_county icc_state county_n) ///
		transform(ln*: exp(@) exp(@)) ///
		eqlabels("" "sd(state)" "sd(county)" "sd(residual)", none) 				

eststo: mixed implicitbias ///
	ppexp_inst stutch_all ///
	i.schoolyear || fips: ||countyid: 
	estat icc
	estadd scalar icc_county= r(icc2)
	estadd scalar icc_state= r(icc3)
	mat define n=e(N_g)
	estadd scalar county_n=n[1,2]
	
	esttab using "$output/an-iat-sensitivity-fullsample.csv", compress nogaps se replace title("Multilevel Models Predicting IAT Scores, Educators only (2009-2016)") ///
		note("Note: All models include random intercepts for county nested within state and year FE.") ///
		scalar(icc_county icc_state county_n) ///
		transform(ln*: exp(@) exp(@)) ///
		eqlabels("" "sd(state)" "sd(county)" "sd(residual)", none) 						
		
eststo: mixed implicitbias ///
	flunchwhtblk percharterwhtblk stutchwhtblk seswhtblk ///
	i.schoolyear || fips: ||countyid: 
	estat icc
	estadd scalar icc_county= r(icc2)
	estadd scalar icc_state= r(icc3)
	mat define n=e(N_g)
	estadd scalar county_n=n[1,2]
	
	esttab using "$output/an-iat-sensitivity-fullsample.csv", compress nogaps se replace title("Multilevel Models Predicting IAT Scores, Educators only (2009-2016)") ///
		note("Note: All models include random intercepts for county nested within state and year FE.") ///
		scalar(icc_county icc_state county_n) ///
		transform(ln*: exp(@) exp(@)) ///
		eqlabels("" "sd(state)" "sd(county)" "sd(residual)", none) 						

eststo: mixed implicitbias ///
	sesall ///
	perblk perhsp /*pctenglish1*/ hswhtblk hsflnfl percharter_all ///
	ppexp_inst stutch_all ///
	flunchwhtblk percharterwhtblk stutchwhtblk seswhtblk ///
	i.schoolyear || fips: ||countyid: 
	estat icc
	estadd scalar icc_county= r(icc2)
	estadd scalar icc_state= r(icc3)
	mat define n=e(N_g)
	estadd scalar county_n=n[1,2]
	
	esttab using "$output/an-iat-sensitivity-fullsample.csv", compress nogaps se replace title("Multilevel Models Predicting IAT Scores, Educators only (2009-2016)") ///
		note("Note: All models include random intercepts for county nested within state and year FE.") ///
		scalar(icc_county icc_state county_n) ///
		transform(ln*: exp(@) exp(@)) ///
		eqlabels("" "sd(state)" "sd(county)" "sd(residual)", none) 								
		
eststo: mixed implicitbias ///
	amind eastasian southasian nathaw black blackwhite multiother otherun ///
	female i.agecat i.ed ///
	sesall ///
	perblk perhsp /*pctenglish1*/ hswhtblk hsflnfl percharter_all ///
	ppexp_inst stutch_all ///
	flunchwhtblk percharterwhtblk stutchwhtblk seswhtblk ///
	i.schoolyear || fips: ||countyid: 
	estat icc
	estadd scalar icc_county= r(icc2)
	estadd scalar icc_state= r(icc3)
	mat define n=e(N_g)
	estadd scalar county_n=n[1,2]
	
	esttab using "$output/an-iat-sensitivity-fullsample.csv", compress nogaps se replace title("Multilevel Models Predicting IAT Scores, Educators only (2009-2016)") ///
		note("Note: All models include random intercepts for county nested within state and year FE.") ///
		scalar(icc_county icc_state county_n) ///
		transform(ln*: exp(@) exp(@)) ///
		eqlabels("" "sd(state)" "sd(county)" "sd(residual)", none) 		
		
log close
